<template>
	<!-- 预览文件页面 -->
	<view>
		<myHead :title="title" :showRightIcon="true" @clickRightIcon="clickRightIcon" :right="false"></myHead>
		<web-view ref="webview" :src="weburl" :fullscreen="false"></web-view>
	</view>
</template>

<script>
	import myHead from "@/pages/component/baseHead.vue";
	import {
		Base64
	} from "node_modules/js-base64/base64.js";
	export default {
		data() {
			return {
				title: "",
				URL: this.$config.domain.staticUrl,
				weburl: "",
				webviewStyles: {
					width: "750",
					height: "600",
				},
				fileType: '',
				titlePictures: ''
			};
		},
		//子组件
		components: {
			myHead,
		},
		onLoad(option) {
			if (option) {
				let suffixSrc = encodeURIComponent(Base64.encode(option.src));
				this.weburl =
					`${this.$config.domain.staticUrl}/fileview/onlinePreview?title=${encodeURIComponent(option.title)}&url=${suffixSrc}`;
				this.title = option.title;
				this.fileType = option.fileType
				console.log(this.fileType);
				if (this.fileType == 'pdf') {
					this.titlePictures = '/static/recruit/home/pdf.png'
				} else {
					this.titlePictures = '/static/recruit/home/word.png'
				}
				console.log('weburl', this.weburl);
			}
		},
		onReady() {
			uni.showLoading({
				title: "加载中..",
			})
			let height = 0; //定义动态的高度变量
			let statusbar = 0; // 动态状态栏高度
			uni.getSystemInfo({
				// 获取当前设备的具体信息
				success: (sysinfo) => {
					console.log(sysinfo);
					statusbar = sysinfo.statusBarHeight + 45;
					height = sysinfo.windowHeight;
				},
			});
			let currentWebview = this.$scope.$getAppWebview(); //获取当前web-view
			this.$nextTick(() => {
				uni.hideLoading();
				var wv = currentWebview.children()[0];
				wv.setStyle({
					//设置web-view距离顶部的距离以及自己的高度，单位为px
					top: statusbar, //此处是距离顶部的高度，应该是你页面的头部
					height: height - statusbar, //webview的高度
					scalable: true, //webview的页面是否可以缩放，双指放大缩小
				});
			}); //如页面初始化调用需要写延迟
		},
		methods: {
			clickRightIcon() {
				console.log("分享");
				const app = getApp()
				let name = app.globalData.user.RealName
				var msg = {
					type: 'web',
					content: name + '的附件简历', // pictures 参数为数组  注意图片路径要是本地路径 base64也可以
					href: this.weburl,
					type: 'image',
					pictures: [this.titlePictures]
				};
				plus.share.sendWithSystem(msg, function() {
					console.log(msg);
					console.log('分享成功');
				});
			}
		}


	};
</script>

<style>
</style>